import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import legacy from '@vitejs/plugin-legacy'
import config from './upload/config'
import transformHtml from './plugin/transformHtml'
import { resolve } from 'path'
import { readdirSync } from 'fs'
// import transformGltf from './plugin/transformGltf'
// https://vitejs.dev/config/
function getEntry() {
  const entry={};
  readdirSync(__dirname).forEach(file=>{
    const fileName = file.match(/^([^\.]+)\.html?$/);
    if(fileName){
      entry[fileName[1]]=resolve(__dirname, fileName[0]);
    }
  });
  return entry;
}
export default defineConfig({
  root:config.projectPath,
  base:`https://${config.tupload.site}${config.tupload.baseUrl}`,
  assetsInclude:/\.(gltf|bin)$/,
  define:{
    "SENTRY_VERSION":JSON.stringify(config.sentry.releasesVersion),
  },
  plugins: [
    vue(),
    legacy(),
    transformHtml(),
    // transformGltf(),
  ],
  build:{
    sourcemap:true,
    rollupOptions: {
      input: getEntry(),
    }
  }
});
